package com.suixun.util;

import java.util.Calendar;
import java.util.Date;

public class OpUtil {
	/**
	 * <p>Title: setDevicePackage</p>
	 * <p> 功能描述:设备套餐转有效期 </p>
	 * @param str "1年":一年送一个月，当月，"2年"：两年送三个月，加上当月
	 * @return
	 */
	public static Date setDevicePackageToEndtime(String str) {
		Calendar calendar = Calendar.getInstance();
		if ("1年".equals(str)) {
			calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 1);
			calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
			calendar.set(Calendar.HOUR_OF_DAY, 23);
			calendar.set(Calendar.MINUTE, 59);
			calendar.set(Calendar.SECOND, 59);
			return calendar.getTime();
		}else if ("2年".equals(str)) {
			calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 2);
			calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + 2);
			calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
			calendar.set(Calendar.HOUR_OF_DAY, 23);
			calendar.set(Calendar.MINUTE, 59);
			calendar.set(Calendar.SECOND, 59);
			return calendar.getTime();
		}
		return null;
	}
	
	/*public static Date setDevicePackageToEndtime(String str) {
		Calendar calendar = Calendar.getInstance();
		String time = null;
		int year = calendar.get(Calendar.YEAR);
		if ("1年".equals(str)) {
			int month = calendar.get(Calendar.MONTH)+2;
			time = (year+1)+"-"+(ExcelUtil.zeroize(String.valueOf(month), 2))+"-01 00:00:00";
		}else if ("2年".equals(str)) {
			int month = calendar.get(Calendar.MONTH)+4;
			time = (year+2)+"-"+(ExcelUtil.zeroize(String.valueOf(month), 2))+"-01 00:00:00";
		}
		return DateUtil.formatStringToTime(time, "yyyy-MM-dd HH:mm:ss");
	}*/
}
